* @todo Add ability to prefer one type of content over another (in a media group).
*/
function get_enclosure($key = 0, $prefer = null)
{
$enclosures = $this->get_enclosures();
if (isset($enclosures[$key]))
{
return $enclosures[$key];
}
else
{
return null;
}
}
/**
* Grabs all available enclosures (podcasts, etc.)
*
* Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
*
* At this point, we're pretty much assuming that all enclosures for an item are the same content. Anything else is too complicated to properly support.
*
* @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
* @todo Add support for itunes: tags. These should be relatively simple compared to media:.
* @todo If an element exists at a level, but it's value is empty, we should fall back to the value from the parent (if it exists).
*/
function get_enclosures()
{
if (!isset($this->data['enclosures']))
{
$this->data['enclosures'] = array();
// Elements
$captions_parent = null;
$categories_parent = null;
$copyrights_parent = null;
$credits_parent = null;
$description_parent = null;
$duration_parent = null;
$hashes_parent = null;
$keywords_parent = null;
$player_parent = null;
$ratings_parent = null;
$restrictions_parent = null;
$thumbnails_parent = null;
$title_parent = null;
// Let's do the channel and item-level ones first, and just re-use them if we need to.
$parent = $this->get_feed();
// CAPTIONS
if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
// A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
if (strpos($input, '../') === 0)
{
$input = substr($input, 3);
}
elseif (strpos($input, './') === 0)
{
$input = substr($input, 2);
}
// B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
elseif (strpos($input, '/./') === 0)
{
$input = substr_replace($input, '/', 0, 3);
}
elseif ($input == '/.')
{
$input = '/';
}
// C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
// D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
elseif ($input == '.' || $input == '..')
{
$input = '';
}
// E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
while ($class1 = strtolower(get_parent_class($class1)))
{
if ($class1 == $class2)
{
return true;
}
}
}
}
else
{
trigger_error('Unknown class passed as parameter', E_USER_WARNNG);
}
}
return false;
}
/**
* Strip HTML comments
*
* @access public
* @param string $data Data to strip comments from
* @return string Comment stripped string
*/
function strip_comments($data)
{
$output = '';
while (($start = strpos($data, '<!--')) !== false)
{
$output .= substr($data, 0, $start);
if (($end = strpos($data, '-->', $start)) !== false)
{
$data = substr_replace($data, '', 0, $end + 3);
}
else
{
$data = '';
}
}
return $output . $data;
}
function parse_date($dt, $rfc822_tz = true)
{
static $cache = array();
if (!isset($cache[$dt][$rfc822_tz]))
{
$dt = SimplePie_Misc::uncomment_rfc822($dt);
/*
Capturing subpatterns:
1: RFC 822 date
2: RFC 822 day
3: RFC 822 month
4: RFC 822 year
5: ISO 8601 date
6: ISO 8601 century
7: ISO 8601 year
8: ISO 8601 month
9: ISO 8601 day
10: ISO 8601 ordinal day
11: ISO 8601 month
12: ISO 8601 day
13: ISO 8601 week
14: ISO 8601 day of week
15: Time
16: Hour
17: Hour Decimal
18: Minute
19: Minute Decimal
20: Second
21: Second Decimal
22: Timezone
23: Diff ┬▒
24: Hour
25: Hour Decimal
26: Minute
27: Minute Decimal
28: Alphabetic Timezone
*/
if (preg_match('/^(?:(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)[,\s]+)?(([0-9]{1,2})\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*([0-9]{4}|[0-9]{2}))|(([0-9]{2})(?:([0-9]{2})(?:(?:-|\s)*(?:([0-9]{2})([0-9]{2})|([0-9]{3})|([0-9]{2})(?:(?:-|\s)*([0-9]{2}))?|W([0-9]{2})(?:(?:-|\s)*([0-9]))?))?)?))((?:T|\s)+([0-9]{2})(?:(?:,|\.)([0-9]*)|(?:\:|\s)*([0-9]{2})(?:(?:,|\.)([0-9]*)|(?:\:|\s)*([0-9]{2})(?:(?:,|\.)([0-9]*))?)?)?(?:\s)*((?:(\+|-)([0-9]{2})(?:(?:,|\.)([0-9]*)|(?:\:|\s)*(?:([0-9]{2})(?:(?:,|\.)([0-9]*))?))?)|(UTC|GMT|EST|CST|MST|PST|EDT|CDT|MDT|PDT|UT|[A-IK-Z]))?)?$/i', $dt, $match))
* @todo Move to using an actual HTML parser (this will allow tags to be properly stripped, and to switch between HTML and XHTML), this will also make it easier to shortern a string while preserving HTML tags